<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>巡检信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="../../css/public.css" media="all" />
</head>
<body class="childrenBody">
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="check_message.js"></script>
<script type="text/html" id="switchTpl">
    <!-- 这里的 checked 的状态只是演示 -->
    <input type="checkbox" name="sex" value="{{ d.id == 10003 ? 'checked' : '' }}" lay-skin="switch" lay-text="女|男" lay-filter="sexDemo">
</script>
<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input searchVal" placeholder="任务名称" />
                </div>
                <a class="layui-btn search_btn" data-type="reload">查询</a>
            </div>
            <div class="layui-inline">
                <a class="layui-btn layui-btn-normal addNews_btn">添加类型</a>
            </div>
            <div class="layui-inline">
                <a class="layui-btn layui-btn-danger layui-btn-normal delAll_btn">批量删除</a>
            </div>
        </form>
    </blockquote>
    <table id="check_message" lay-filter="check_message"></table> 
	<!--操作-->
<!--    <a class="layui-btn layui-btn-xs" lay-event="edit">查看</a>-->
    <div id="check_option">

    </div>
<!--	<script id="check_messageBar">-->
<!--        {{#  if(document.getElementById("status").val() == "已完成"){ }}-->
<!--        document.getElementById("check_option").innerHTML =" <a class="layui-btn layui-btn-xs" lay-event="edit">查看</a>"-->
<!--        {{#   }else { }}-->
<!--         document.getElementById("check_option").innerHTML ="<p>待执行</p>"-->
<!--        {{#  } }}-->
<!--    </script>-->
</form>
<!--<script type="text/javascript" src="../../layui/layui.js"></script>-->
<!--<script type="text/javascript" src="check_message.js"></script>-->
<!--修改-->
<script type="text/javascript">
      layui.use(['form','layer','table','laytpl'],function(){
          var form = layui.form,
              layer = parent.layer === undefined ? layui.layer : top.layer,
              $ = layui.jquery,
              laytpl = layui.laytpl,
              table = layui.table;

          //用户列表
          var tableIns = table.render({
              elem: '#check_message',
              url : '../../json/check_message.json',
              cellMinWidth : 95,
              page : true,
              height : "full-125",
              limits : [10,15,20,25],
              limit : 20,
              id : "check_messageTable",
              cols : [[
                  {type: "checkbox", fixed:"left", width:50},
                  {field: 'taskName', fixed:"left",title: '任务名称', minWidth:100, align:'center'},
                  {field: 'taskType', title: '任务类型', align:'center'},
                  {field: 'checkItem', title: '检验项', align:'center'},
                  {field: 'taskContent', title: '任务内容', align:'center'},
                  {field: 'founder', title: '创建者', align:'center'},
                  {field: 'Time', title: '创建时间', align:'center', minWidth:150},
                   {field:'status', title:'完成状态', width:85, templet: '#switchTpl', unresize: true},
<!--                  //{field: 'status', title: '完成状态', align:'center',id:'status',templet:function (d) {-->
<!--                        return d.sex==true?'<a class="layui-btn layui-btn-xs" lay-event="edit">查看</a>':'<p>待执行</p>'-->
<!--                    }},-->
                 // {field: 'operation', title: '操作', align:'center'}
                  {title: '操作', minWidth:175,templet:function (d) {
                        return d.status=="待执行"?'<a class="layui-btn layui-btn-xs" lay-event="edit">查看</a>':'<p>待执行</p>'
                    }},

              ]]
          });
<!--        function check(){-->
<!--           {{#  if(document.getElementById("status").val() == "已完成"){ }}-->
<!--           document.getElementById("check_option").innerHTML =" <a class="layui-btn layui-btn-xs" lay-event="edit">查看</a>"-->
<!--           {{#   }else { }}-->
<!--           document.getElementById("check_option").innerHTML ="<p>待执行</p>"-->
<!--           {{#  } }}-->
<!--          }-->
//		 //监听性别操作
<!--//           form.on('switch(sexDemo)', function(obj){-->
<!--//           var sex = $(".sexDemo").val()，-->
<!--//           if(sex === 'true'){-->
<!--//                 <a class="layui-btn layui-btn-xs" lay-event="edit">查看</a>-->
<!--//           }-->
<!--//            layer.msg(obj.elem.checked),-->
<!--//             layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);-->
<!--//           });-->


          //搜索【此功能需要后台配合，所以暂时没有动态效果演示】
          $(".search_btn").on("click",function(){
              if($(".searchVal").val() != ''){
                  table.reload("check_messageTable",{
                      page: {
                          curr: 1 //重新从第 1 页开始
                      },
                      where: {
                          key: $(".searchVal").val()  //搜索的关键字
                      }
                  })
              }else{
                  layer.msg("请输入搜索的内容");
              }
          });

          //添加用户
          function addUser(edit){
              var index = layui.layer.open({
                  title : "添加类型",
                  type : 2,
                  content : "checkAddMessage.html",
                  success : function(layero, index){
                      var body = layui.layer.getChildFrame('body', index);
                      if(edit){
                          body.find(".taskName").val(edit.taskName);  //任务类型名

                          body.find(".userGrade").val(edit.userGrade);  //会员等级

                          form.render();
                      }
                      setTimeout(function(){
                          layui.layer.tips('点击此处返回用户列表', '.layui-layer-setwin .layui-layer-close', {
                              tips: 3
                          });
                      },500)
                  }
              })
              layui.layer.full(index);
              window.sessionStorage.setItem("index",index);
              //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
              $(window).on("resize",function(){
                  layui.layer.full(window.sessionStorage.getItem("index"));
              })
          }
          $(".addNews_btn").click(function(){
              addUser();
          })

          //批量删除
          $(".delAll_btn").click(function(){
              var checkStatus = table.checkStatus('userListTable'),
                  data = checkStatus.data,
                  newsId = [];
              if(data.length > 0) {
                  for (var i in data) {
                      newsId.push(data[i].newsId);
                  }
                  layer.confirm('确定删除选中的用户？', {icon: 3, title: '提示信息'}, function (index) {
                      // $.get("删除文章接口",{
                      //     newsId : newsId  //将需要删除的newsId作为参数传入
                      // },function(data){
                      tableIns.reload();
                      layer.close(index);
                      // })
                  })
              }else{
                  layer.msg("请选择需要删除的用户");
              }
          })

          //列表操作
          table.on('tool(check_message)', function(obj){
              var layEvent = obj.event,
                  data = obj.data;

              if(layEvent === 'edit'){ //编辑
                  addUser(data);
              }else if(layEvent === 'usable'){ //启用禁用
                  var _this = $(this),
                      usableText = "是否确定禁用此用户？",
                      btnText = "已禁用";
                  if(_this.text()=="已禁用"){
                      usableText = "是否确定启用此用户？",
                      btnText = "已启用";
                  }
                  layer.confirm(usableText,{
                      icon: 3,
                      title:'系统提示',
                      cancel : function(index){
                          layer.close(index);
                      }
                  },function(index){
                      _this.text(btnText);
                      layer.close(index);
                  },function(index){
                      layer.close(index);
                  });
              }else if(layEvent === 'del'){ //删除
                  layer.confirm('确定删除此用户？',{icon:3, title:'提示信息'},function(index){
                      // $.get("删除文章接口",{
                      //     newsId : data.newsId  //将需要删除的newsId作为参数传入
                      // },function(data){
                          tableIns.reload();
                          layer.close(index);
                      // })
                  });
              }
          });

      })
</script>
</body>
</html>